﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using DAL.Entities;

namespace DAL
{
     public class PublicarDAL : DBController
    {

         public List<PublicarEntityRes> GetGrouponAPublicarByProveedor(PublicarEntityReq pro)
         {
             try
             {
                 List<PublicarEntityRes> groupons = new List<PublicarEntityRes>();
                 using (SqlConnection conn = this.OpenConn())
                 {

                     SqlDataReader dr;

                     SqlCommand dCmd = new SqlCommand("MARAVILLA_SQL.spGetGrouponAPublicarByProveedor", conn);

                     dCmd.CommandText = "MARAVILLA_SQL.spGetGrouponAPublicarByProveedor";

                     dCmd.CommandType = CommandType.StoredProcedure;

                     dCmd.Parameters.AddWithValue("@date", pro.actualDate);
                     dCmd.Parameters.AddWithValue("@intIdProveedor", pro.IntIdProveedor);

                     // dCmd.ExecuteNonQuery();
                     dr = dCmd.ExecuteReader();
                     dCmd.Dispose();
                     if (dr.HasRows)
                     {
                         while (dr.Read())
                         {
                             PublicarEntityRes gru = new PublicarEntityRes();
                             gru.VarCodigo = dr["varCodigo_Groupon"].ToString();
                             gru.VarDescripcion = dr["varDescripcion"].ToString();
                             groupons.Add(gru);
                         }
                     }
                 }
                 return groupons;

             }
             catch (Exception ex)
             {
                 throw ex;
             }
         }

         public List<PublicarEntityRes> GetGrouponAPublicar(PublicarEntityReq pro)
          {
              try
              {
                  List<PublicarEntityRes> groupons = new List<PublicarEntityRes>();
                  using (SqlConnection conn = this.OpenConn())
                  {

                      SqlDataReader dr;

                      SqlCommand dCmd = new SqlCommand("MARAVILLA_SQL.spGetGrouponAPublicar", conn);

                      dCmd.CommandText = "MARAVILLA_SQL.spGetGrouponAPublicar";

                      dCmd.CommandType = CommandType.StoredProcedure;

                      dCmd.Parameters.AddWithValue("@date", pro.actualDate.Day+"/"+pro.actualDate.Month + "/"+pro.actualDate.Year);

                      // dCmd.ExecuteNonQuery();
                      dr = dCmd.ExecuteReader();
                      dCmd.Dispose();
                      if (dr.HasRows)
                      {
                          while (dr.Read())
                          {
                              PublicarEntityRes gru = new PublicarEntityRes();
                              gru.VarCodigo = dr["varCodigo_Groupon"].ToString();
                              gru.VarDescripcion = dr["varDescripcion"].ToString();
                              groupons.Add(gru);
                          }
                      }
                  }
                  return groupons;

              }
              catch (Exception ex)
              {
                  throw ex;
              }
          }


          public bool PublicarGrupon(Entities.PublicarEntityRes gru)
          {
              try
              {
                  using (SqlConnection conn = this.OpenConn())
                  {

                      SqlCommand dCmd = new SqlCommand("MARAVILLA_SQL.spPublicarGroupon", conn);

                      dCmd.CommandText = "MARAVILLA_SQL.spPublicarGroupon";

                      dCmd.CommandType = CommandType.StoredProcedure;


                      dCmd.Parameters.AddWithValue("@varCodigo_Groupon", gru.VarCodigo);

                      // dCmd.ExecuteNonQuery();
                      dCmd.ExecuteNonQuery();
                      dCmd.Dispose();
                  }
                  return true;

              }
              catch (Exception ex)
              {
                  throw ex;
              }
          }


        }
 }

